package com.cqb.cn.common.Exception;

import com.cqb.cn.common.api.BaseResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;


/**
 * @project_name: hqbz
 * @package_name: com.htsy.hqbz.common.api
 * @ClassName: GlobalExceptionHandler
 * @description: 全局异常处理
 * Author by cqb, Date on 2020/9/18，21:38
 * PS: Not easy to write code, please indicate.
 */
@ControllerAdvice
@Slf4j
public class GlobalExceptionHandler {
    /**
     * 处理系统内部异常
     * @param e
     * @return
     */
    @ExceptionHandler(Exception.class)
    public BaseResponse handleException(Exception e){
        return ResultUtil.getError(ResultEnum.SystemException.getCode(),
                ResultEnum.ServiceException.getMsg());
    }

    /**
     * 处理自定义异常
     * @param e
     * @return
     */
    @ExceptionHandler(MyException.class)
    public BaseResponse handleMyException(MyException e){
        return ResultUtil.getError(e.getCode(), e.getMessage());
    }
}
